package com.cn.hotel.servlet.back.user;

import com.cn.hotel.model.UserModel;
import com.cn.hotel.service.IUserService;
import com.cn.hotel.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@WebServlet("/back/user/userEdit")
public class userEditServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //1、得到页面传递过来的值
        String idString = req.getParameter("id");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String code = req.getParameter("code");
        String phone = req.getParameter("phone");
        String sex = req.getParameter("sex");
        String birthday = req.getParameter("birthday");
        String hobby = req.getParameter("hobby");
        String introduce = req.getParameter("introduce");
        //2、将得到的值封装到实体类
        UserModel userModel = new UserModel();
        userModel.setId(idString==null||"".equals(idString)?0:Integer.parseInt(idString));//三元运算符 对idString进行判断是否为空。
        userModel.setUsername(username);
        userModel.setPassWord(password);
        userModel.setPhone(phone);
        userModel.setSex(sex);
        userModel.setBirthday(birthday);
        userModel.setHobby(hobby);
        userModel.setIntroduce(introduce);
        //3、服务逻辑层实例化service
        IUserService iUserService = new UserServiceImpl();
        int count = iUserService.edit(userModel);
        resp.getWriter().println(count);
    }
}
